package com.globallogic.strelchuk.multi.entity;

import java.util.ArrayList;
import java.util.List;

import com.globallogic.strelchuk.multi.exception.TableSizeException;
import com.globallogic.strelchuk.multi.util.Formatter;

/**
 * @author olena.strelchuk
 */

/**
 * Triangle Multiplication Table
 */
public class TriangleMultiplicationTable extends AbstractMultiplicationTable {

	private List<Row> rowList;

	public TriangleMultiplicationTable(int tableSize) throws TableSizeException {
		super(tableSize);
	}
	
	/**
	 * Initialize Triangle Table
	 */
	@Override
	public void initTable() {
		rowList = new ArrayList<Row>(getTableSize());
		fillRowList();
	}

	/**
	 * Generate MultiplicationTable with specified table size
	 */
	private void fillRowList() {
		for (int i = 1; i <= getTableSize(); i++) {
			Row row = new Row(i, i);
			rowList.add(row);
		}
	}

	/**
	 * toString Method for MultiplicationTable
	 */
	@Override
	public String toString() {
		return Formatter.formatTriangleTable(this);		
	}

	public List<Row> getRowList() {
		return rowList;
	}
}
